package com.topboya.linker.ui.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.topboya.linker.R;
import com.topboya.linker.diyview.group.GroupItemDecoration;
import com.topboya.linker.diyview.group.GroupRecyclerView;
import com.topboya.linker.model.response.OrganizationResopnse;
import com.topboya.linker.ui.adapter.RecycleViewDivider;
import com.topboya.linker.ui.adapter.xAuditedAdapter;
import com.topboya.linker.ui.adapter.xUnAuditedGroupAdapter;
import com.topboya.linker.ui.base.Presenter.BasePresenter;
import com.topboya.linker.ui.base.activity.BaseActivity;
import com.topboya.linker.ui.base.fragment.BaseFragment;
import com.topboya.linker.ui.presenter.MyCustomerPresenter;
import com.topboya.linker.ui.view.MyCustomerView;
import com.topboya.linker.utils.LogUtils;

import java.util.ArrayList;
import java.util.List;

public class UnAuditedFragment extends BaseFragment<MyCustomerView, MyCustomerPresenter> implements MyCustomerView{

    private static final String TAG = "UnAuditedFragment";
    private GroupRecyclerView ryc_unaudited;
    private  int pageNO =1;
    private List<OrganizationResopnse.DocDetailInfoList> docDetailInfoListsunpass;
    private List<OrganizationResopnse.DocDetailInfoList> docDetailInfoListsunpassing;
    private List<OrganizationResopnse.DocDetailInfoList> docDetailInfoListsunpassall;
    private xUnAuditedGroupAdapter xUnAuditedGroupAdapter;
    private SmartRefreshLayout smart_refreshlayout;
    @Override
    protected int getLayoutId() {

        return R.layout.fragment_unaudited;
    }

    @Override
    protected void initView() {

        ryc_unaudited = mRootView.findViewById(R.id.ryc_unaudited);
        smart_refreshlayout = mRootView.findViewById(R.id.smart_refreshlayout);
        smart_refreshlayout.setEnableRefresh(false);

    }

    @Override
    protected void initData() {

        docDetailInfoListsunpass = new ArrayList<>();
        docDetailInfoListsunpassing = new ArrayList<>();
        docDetailInfoListsunpassall = new ArrayList<>();
        initRecycleView();

    }

    private void initRecycleView() {

        mPresenter.getOrgList(String.valueOf(pageNO),null,"3");
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
        ryc_unaudited.setLayoutManager(layoutManager);
//        ryc_unaudited.addItemDecoration(new RecycleViewDivider(getActivity(), LinearLayoutManager.HORIZONTAL, 2, 0xBFC0C2));
        ryc_unaudited.addItemDecoration(new GroupItemDecoration<String, String>());
        xUnAuditedGroupAdapter = new xUnAuditedGroupAdapter(getActivity(),docDetailInfoListsunpass,docDetailInfoListsunpassing);
        ryc_unaudited.setAdapter(xUnAuditedGroupAdapter);
        ryc_unaudited.notifyDataSetChanged();
    }
    @Override
    public void initListener() {

        smart_refreshlayout.setOnLoadmoreListener(refreshlayout -> {

            pageNO++;
            mPresenter.getOrgList(String.valueOf(pageNO),null,"3");

        });
    }
    @Override
    protected MyCustomerPresenter createPresenter() {


        return new MyCustomerPresenter((BaseActivity) getActivity());
    }


    @Override
    public void setCustomeData(ArrayList<OrganizationResopnse.DocDetailInfoList> groupHList) {

           docDetailInfoListsunpass.clear();
           docDetailInfoListsunpass.addAll(groupHList);
           LogUtils.v(TAG + "groupHList1:"+groupHList.toString());
           mPresenter.getOrgListInAudited("0",null,"2");
    }

    @Override
    public void getOrgListInAudited(ArrayList<OrganizationResopnse.DocDetailInfoList> groupHList) {
        LogUtils.v(TAG + "groupHList2:"+groupHList.toString());

        docDetailInfoListsunpassing.addAll(groupHList);
        docDetailInfoListsunpassall.addAll(docDetailInfoListsunpass);
        docDetailInfoListsunpassall.addAll(docDetailInfoListsunpassing);
        xUnAuditedGroupAdapter.resetGroups();
        xUnAuditedGroupAdapter.setItemData(docDetailInfoListsunpassall);
        ryc_unaudited.notifyDataSetChanged();
        smart_refreshlayout.finishLoadmore();


    }
}
